﻿#coding=utf-8
from django.db import connection


def GetLabel(flag=1):
	cur=connection.cursor()
	cur.execute("set names utf8")
	cur.execute("select distinct label from attention_titleinfo where isdel=1 order by label")
	result=cur.fetchall()
	cur.close()
	if flag==1:
		return result
	else:
		returnInfo=[]
		for one in result:
			returnInfo.append((one[0],one[0]))
		return returnInfo
	
def GetTitle(labelname):
	cur=connection.cursor()
	#cur.execute("set names utf8")
	cur.execute("call sp_GetTitle('%s')"%(labelname))
	result=cur.fetchall()
	cur.close()
	return result
	
def GetTitle_search(searchInfo):
	cur=connection.cursor()
	cur.execute("call sp_GetTitle_search('%s')"%searchInfo)
	result=cur.fetchall()
	cur.close()
	return result
	
def GetContent(idx):
	cur=connection.cursor()
	cur.execute("set names utf8")
	cur.execute("select content from attention_contentinfo where id=%s"%idx)
	content=cur.fetchone()[0]
	cur.execute("select title from attention_titleinfo where id=%s"%idx)
	mytitle=cur.fetchone()[0]
	cur.close()
	return mytitle,content
	
def SaveArtical(idx,OneArtical):
	cur=connection.cursor()
	cur.execute("call SaveArtical(%s,'%s','%s','%s','%s')"%(idx,OneArtical['title'],OneArtical['label'],OneArtical['newLabel'],OneArtical['content']))
	newid=cur.fetchone()[0]
	cur.nextset()
	cur.execute("commit")
	cur.close()
	return newid

def GetArtical(idx):
	cur=connection.cursor()
	cur.execute("call sp_getArtical(%s)"%idx)
	result=cur.fetchone()
	cur.close()
	OneArtical={
		'title':result[0],
		'label':result[1],
		'content':result[2]
	}
	return OneArtical
	
def DelArtical(idx):
	cur=connection.cursor()
	cur.execute("update attention_titleinfo set isdel=0 where id=%s"%idx)
	cur.execute("commit")
	cur.close()